<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "user_invite".
 *
 * @property integer $uid
 * @property string $invite
 * @property string $invite_f
 */
class UserInvite extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_invite';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['uid','invite_f'], 'required', 'on'=>'create'],
            [['uid','invite_f','invite'], 'required', 'on'=>'update'],
            [['uid'], 'integer'],
            [['invite'], 'unique'],
            [['invite', 'invite_f'], 'match', 'pattern'=>'/^[a-zA-Z0-9_]{6}$/', 'message'=>'{attribute}只能由6位英文字母、数字、下划线组成']
        ];
    }

    public function scenarios()
    {
        $scenarios = parent::scenarios();
        $scenarios['create'] = ['uid','invite_f'];
        $scenarios['update'] = ['uid','invite_f','invite'];
        return $scenarios;
    }
    
    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'uid' => Yii::t('app', 'User Id'),
            'invite' => Yii::t('app', 'Invite Code'),
            'invite_f' => Yii::t('app', 'Invite F'),
        ];
    }
    /*获得邀请的所有uid*/
    public static function get_invite_all_users($uid){
		$invite_info = self::findOne(['uid'=>$uid]);
		$invite = $invite_info['invite'];
		$all_user = self::find()->select('uid')->where(['invite_f'=>$invite])->all();
		return $all_user;
    }
}
